package com.cloud.sso.common.exception.handler;

import com.cloud.sso.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ControllerAdvice
@Order(2147483647)
@ResponseBody
public class GlobalExceptionHandler {

    /**
     * 拦截业务异常并且记录
     *
     * @param request
     * @param response
     * @param exception
     * @return
     */
  /*  @ExceptionHandler(Exception.class)
    public Result<String> handle(HttpServletRequest request, HttpServletResponse response, AppException exception) {
        log.error(exception.getMessage());

        Result result = Result.error(500, exception.getMessage(), false);
        result.setData(exception.getMessage());
        return result;
    }*/

    @ExceptionHandler(Exception.class)
    public Result<String> exceptionHandler(Exception exception) {
        log.error(exception.getMessage());

        Result result = Result.error(exception.getMessage(), false);
        result.setData(exception.getMessage());
        return result;
    }



}
